/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ForOutputsTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.nc.kyiv.yellow.sociallibrary.emails.EmailSender;

/**
 *
 * @author Виталий
 */
public class TestSendEmail extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String text = request.getParameter("text");
        String file = request.getParameter("url");
        String ch = request.getParameter("ch");
        String to = request.getParameter("to");
        String topic = request.getParameter("topic");
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Send</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<form name=\"sendform\" action=\"Send\" method=\"post\">");
            out.println("Send Email to:<br><input type=\"text\" name=\"to\"><br>");
            out.println("Topic:<br><input type=\"text\" name=\"topic\"><br>");
            out.println("Choose type:<br><input type=\"radio\" name=\"ch\" value=\"file\" onclick=\"document.getElementById('file').style.display='block';document.getElementById('text').style.display='none';\">File<br><input type=\"radio\" name=\"ch\" value=\"text\" onclick=\"document.getElementById('file').style.display='none';document.getElementById('text').style.display='block';\">Text<br>");
            out.println("<div id=\"text\" style=\"display:none;\">Text:<br><textarea name=\"text\" rows=\"5\" cols=\"30\"></textarea></div>");
            out.println("<div id=\"file\" style=\"display:none;\">Path to file:<input type=\"text\" name=\"url\" value=\"file:///C:/Users/Виталий/Documents/NetBeansProjects/SocLib/email.html\"  ></div>");
            out.println("<br><input type=\"submit\" value=\"Send\"><br><br>");
            out.println("</form>");
            EmailSender ES = new EmailSender();
            ES.Confirmation("vspivak94@gmail.com", "_name_", "_login_","http://vk.com");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
